#ifndef COMMON_CACHE_H
#define COMMON_CACHE_H 1

#include <common/common.h>
#include <common/avltree.h>
#include <common/linkedlist.h>

typedef void(*cache_removal_f)(void *, void *, void *);

typedef struct cache_t {
	avltree_t     *data;
	int                  maxnodes;

	linked_list_t *lrulist;

	cache_removal_f removal_f;
	void *ctx;
} cache_t;

typedef struct cache_item_t {
	linked_list_item_t *lruitem;
	void                      *data;
} cache_item_t;

API_LIBLOCAL cache_t *cache_new(int, generic_cmp_f);
API_LIBLOCAL void cache_set_callback(cache_t *, cache_removal_f, void *);
API_LIBLOCAL void cache_flush(cache_t *);
API_LIBLOCAL void cache_destroy(cache_t *);
API_LIBLOCAL int cache_insert(cache_t *, void *, void *);
API_LIBLOCAL int cache_lookup(cache_t *, void *, void **);

#endif
